package com.smalldoor.thread.demo03;

// 设置标志位来停止线程
public class StopThread implements Runnable{

    private boolean flag = true;

    @Override
    public void run() {
        int i = 0;
        while (flag) {
            System.out.println("实现runnable的当前的标志位为：" + i++);
        }
    }

    public void stop() {
        this.flag = false;
    }

    public static void main(String[] args) {
        StopThread stopThread = new StopThread();

        new Thread(stopThread).start();

        for (int i = 0; i < 100; i++) {
            System.out.println("主程序的标志位为：" + i);
            if (i == 65) {
                stopThread.stop();
                System.out.println("线程停止！");
            }
        }
    }
}
